package cn.edu.scnu.user.service;

import cn.edu.scnu.pojo.Organizer;
import cn.edu.scnu.user.mapper.OrgMapper;
import cn.edu.scnu.user.mapper.UserMapper;
import cn.edu.scnu.vo.OrganizerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class OrgService {
    @Autowired
    private OrgMapper orgMapper;

    @Autowired
    private UserMapper userMapper;

    public void saveOrg(Organizer user) {
        orgMapper.saveOrg(user);
    }

    public OrganizerVO getOrgByUname(String username) {
        OrganizerVO organizerVO = orgMapper.getOrgByUname(username);
        if (organizerVO != null) {
            Map<String, String> info = userMapper.getInfoByUsername(username);
            organizerVO.setNickname(info.get("nickname"));
            organizerVO.setImgurl(info.get("imgurl"));
            return organizerVO;
        }
        return null;
    }

    public OrganizerVO getOrgById(String userId) {
        OrganizerVO organizerVO = orgMapper.getOrgById(userId);
        if (organizerVO != null) {
            Map<String, String> info = userMapper.getInfoByUsername(organizerVO.getUsername());
            organizerVO.setNickname(info.get("nickname"));
            organizerVO.setImgurl(info.get("imgurl"));
            return organizerVO;
        }
        return null;
    }
}
